﻿namespace EFS.RC.Wallboard.Common.Functions
{
	public static class DateTime
	{
		/// Returns the time span as formated
		public static System.String GetFormated(System.TimeSpan span)
		{
			// create time span
			System.TimeSpan tsLength = span;

			// create length text
			System.Text.StringBuilder sbLength = new System.Text.StringBuilder();

			// DAYS
			if (tsLength.Days > 0)
			{
				sbLength.AppendFormat("{0}d", tsLength.Days);
			}

			// HOURS
			if (tsLength.Hours > 0)
			{
				if (sbLength.Length > 0)
				{
					sbLength.Append(" ");
				}
				sbLength.AppendFormat("{0}h", tsLength.Hours);
			}

			// MINUTES
			if (tsLength.Minutes > 0)
			{
				if (sbLength.Length > 0)
				{
					sbLength.Append(" ");
				}
				sbLength.AppendFormat("{0}m", tsLength.Minutes);
			}

			// SECONDS
			if (0 == sbLength.Length || tsLength.Seconds > 0)
			{
				if (sbLength.Length > 0)
				{
					sbLength.Append(" ");
				}
				sbLength.AppendFormat("{0}s", tsLength.Seconds);
			}

			// conversation length
			return sbLength.ToString();
		}
	}

}